package cn.yunlang.zhangZhongFei.controller;

import cn.yunlang.zhangZhongFei.entity.User;
import cn.yunlang.zhangZhongFei.service.UserService;
import cn.yunlang.zhangZhongFei.util.JwtUtil;
import cn.yunlang.zhangZhongFei.vo.request.TokenRequest;
import cn.yunlang.zhangZhongFei.vo.response.R;
import io.jsonwebtoken.Claims;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "用户模块")
@RestController
@RequestMapping("/user")
public class UserController {

  @Resource private UserService userService;
  @Resource private RedisTemplate<String, Object> redisTemplate;

  @ApiOperation("查询当前登录用户信息")
  @PostMapping("/queryUserDetails")
  public R<User> queryUserDetails() {
    return R.success(userService.queryUserDetailsByUserId(Long.valueOf(new JwtUtil().getUserId())));
  }

  @ApiOperation("修改当前登录用户信息")
  @PostMapping("updateUserDetails")
  public R<User> updateUserDetails(@RequestBody User user) {
    user.setId(Long.valueOf(new JwtUtil().getUserId()));
    userService.updateUserDetailsByUserId(user);
    return R.success();
  }
}
